/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.viweb.storemanager.entity;

import com.viweb.storemanager.core.PropertyIndex;
import com.viweb.storemanager.core.SafeObject;
import java.text.Collator;
import java.text.RuleBasedCollator;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;

/**
 *
 * @author nhchung
 */
public class SaleInvoice extends BaseEntity implements Comparable, Cloneable, SafeObject, PropertyIndex {

    //khai báo biến
    protected Object cloner;
    private Customer customer;
    private Date date;
    private Employee employee;
    private String buyer;
    private double paid;
    private String tranportation;
    private String tranportphone;
    private double tranportcost;
    private boolean isbillable;
    private ArrayList<SaleDetail> saleDetails = new ArrayList<SaleDetail>();
    //khai báo hàm khởi tạo

    public SaleInvoice() {
    }

    public SaleInvoice(int id) {
        setId(id);
    }

    /**
     * @return the customer
     */
    public Customer getCustomer() {
        return customer;
    }

    /**
     * @param customer the customer to set
     */
    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    /**
     * @return the date
     */
    public Date getDate() {
        return date;
    }

    /**
     * @param date the date to set
     */
    public void setDate(Date date) {
        this.date = date;
    }

    /**
     * @return the employee
     */
    public Employee getEmployee() {
        return employee;
    }

    /**
     * @param employee the employee to set
     */
    public void setEmployee(Employee employee) {
        this.employee = employee;
    }

    /**
     * @return the buyer
     */
    public String getBuyer() {
        return buyer;
    }

    /**
     * @param buyer the buyer to set
     */
    public void setBuyer(String buyer) {
        this.buyer = buyer;
    }

    /**
     * @return the paid
     */
    public double getPaid() {
        return paid;
    }

    /**
     * @param paid the paid to set
     */
    public void setPaid(double paid) {
        this.paid = paid;
    }

    /**
     * @return the tranportation
     */
    public String getTranportation() {
        return tranportation;
    }

    /**
     * @param tranportation the tranportation to set
     */
    public void setTranportation(String tranportation) {
        this.tranportation = tranportation;
    }

    /**
     * @return the tranportcost
     */
    public double getTranportcost() {
        return tranportcost;
    }

    /**
     * @param tranportcost the tranportcost to set
     */
    public void setTranportcost(double tranportcost) {
        this.tranportcost = tranportcost;
    }

    /**
     * @return the isbillable
     */
    public boolean isIsbillable() {
        return isbillable;
    }

    /**
     * @param isbillable the isbillable to set
     */
    public void setIsbillable(boolean isbillable) {
        this.isbillable = isbillable;
    }

    public ArrayList<SaleDetail> getSaleDetails() {
        return saleDetails;
    }

    public void setSaleDetails(ArrayList<SaleDetail> saleDetails) {
        this.saleDetails = saleDetails;
    }

    public Object getCloner() {
        return this.cloner;
    }

    public boolean validate() {

        return true;
    }

    public Object getPropertyValue(int index) {
        String value = "";
        switch (index) {
            case 1:
                value = String.valueOf(getId());
                break;
            case 2:
                value = getCustomer().getName();
                break;
            case 3:
                value = getDate().toString();
                break;
            case 4:
                value = getEmployee().getName();
                break;
            case 5:
                value = getBuyer();
                break;
            case 6:
                value = String.valueOf(getPaid());
                break;
            case 7:
                value = getTranportation();
                break;
            case 8:
                value = String.valueOf(getTranportcost());
                break;
            case 9:
                value = String.valueOf(isIsbillable());
                break;
            case 10:
                value = getDatemodifies().toString();
                break;
            case 11:
                value = String.valueOf(getStatus());
                break;
            case 12:
                value = getNote();
                break;
        }
        return value;
    }

    public void setPropertyValue(int index, Object value) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Class getPropertyClass(int index) {
        return String.class;
    }

    /**
     * @return the tranporthone
     */
    public String getTranportPhone() {
        return tranportphone;
    }

    /**
     * @param tranporthone the tranporthone to set
     */
    public void setTranportPhone(String tranportPhone) {
        this.tranportphone = tranportPhone;
    }

    public int compareTo(Object object) {
        if (!(object instanceof WareHouse)) {
            throw new ClassCastException("Ngoại lệ: đối tượng thức uống không hợp lệ!");
        }

        RuleBasedCollator viCollator = (RuleBasedCollator) Collator.getInstance(new Locale("vi"));
        return viCollator.compare(this.getId(), ((SaleInvoice) object).getId());
    }

    public void backup() {
        try {
            this.cloner = this.clone();
        } catch (CloneNotSupportedException ex) {
        }
    }

    public void restore() {
        this.setId(((SaleInvoice) getCloner()).getId());
    }

    @Override
    public String toString() {
        return String.valueOf(this.getId());
    }
}
